package com.jintoufs.web.action.scene;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jintoufs.dao.QueryFilters;
import com.jintoufs.dao.QueryRule;
import com.jintoufs.dao.scene.SceneOrderDetailMapper;
import com.jintoufs.domain.customer.Customer;
import com.jintoufs.domain.scene.Scene;
import com.jintoufs.domain.scene.SceneOrder;
import com.jintoufs.domain.scene.SceneOrderDetail;
import com.jintoufs.logAnnotation.SystemControllerLog;
import com.jintoufs.service.scene.SceneOrderService;
import com.jintoufs.service.scene.SceneService;
import com.jintoufs.web.action.shiro.bind.annotation.CurrentUser;
import com.jintoufs.web.action.support.JqgridPage;
import com.jintoufs.web.action.support.SupportAction;
import org.cosmos.modules.web.msg.AjaxMsg;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("scene/order")
public class SceneOrderAction extends SupportAction {
    @Resource
    private SceneOrderService sceneOrderService;
    @Resource
    private SceneOrderDetailMapper sceneOrderDetailMapper;
    @Resource
    private SceneService sceneService;

    @RequestMapping("list")
    public String list(Model model) {
        return "scene/order/list";
    }

    @RequestMapping("query")
    @ResponseBody
    @SystemControllerLog(description = "获取鱼·定制订单列表")
    public JqgridPage query(int page,
                            int rows, String sidx,
                            String sord,
                            String filters) {
        PageHelper.startPage(page, rows);
        QueryFilters filters_;
        if (filters == null || filters.trim().isEmpty()) {
            filters_ = new QueryFilters();
        } else {
            filters_ = JSON.parseObject(filters, QueryFilters.class);
        }
        filters_.setSidx(sidx);
        filters_.setSord(sord);

        List<Map<String,Object>> hotels = sceneOrderService.selectByFilter(filters_);
        PageInfo pageInfo = new PageInfo(hotels);
        return new JqgridPage(pageInfo.getTotal(), pageInfo.getPages(), pageInfo.getPageNum(),
                pageInfo.getList());
    }
    @RequestMapping(value="/detail")
    public String detail(String id, Model model) {
        Map<String,Object> param = new HashMap<>();
        SceneOrderDetail sceneOrderDetail = sceneOrderDetailMapper.selectBySceneOrderId(id).get(0);
        SceneOrder sceneOrder = sceneOrderService.getById(id);
        Map<String, Object> scene = sceneService.getById(sceneOrder.getSceneId());
        model.addAttribute("orderDetail", sceneOrderDetail);
        model.addAttribute("sceneOrder", sceneOrder);
        model.addAttribute("scene", scene);
        return "scene/order/detail";
    }
}
